package pl.edu.agh.abd.hsm;

import java.rmi.RemoteException;

import org.restlet.Component;
import pl.edu.agh.abd.hsmest.*;
import org.restlet.data.Protocol;
import org.restlet.resource.Get;
import org.restlet.resource.ServerResource;
public class EstimatorService extends ServerResource {

	Estimator estimator = new Estimator();
	
	
	public static void main(String[] args) throws Exception {
		//Create a new Restlet component and add a HTTP server connector to it
		Component component = new Component();
		component.getServers().add(Protocol.HTTP, 8182);
		component.getDefaultHost().attach("/estimator", EstimatorService.class);
		component.start();
	
		System.out.println("Server started");

	}

	@Get("json")
	public EstimatorResponse toJson() {
		EstimatorResponse es = null;
		try {
			es = estimator.estimate(getReference().getRemainingPart());
		} catch (RemoteException e) {
			es = new EstimatorResponse();
			es.setTransferTime(-1);
		}
		//es = new EstimatorResponse();	
		//es.setResourceName(getReference().getRemainingPart().substring(1));
		//es.setLatencyTime(100);
		//es.setTransferTime(102);
		return es;
	}

}
